#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
    freopen("arena.in", "r", stdin);
    freopen("arena.out", "w", stdout);
    int n, m;
    cin >> n >> m;
    int a[n], c[m];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= m; i++)
        cin >> c[i];
    int pw[20];
    pw[0] = 1;
    for (int i = 1; i <= 20; i++)
        pw[i] = pw[i - 1] * 2;
    int T;
    cin >> T;
    while (T--) {
        int x0, x1, x2, x3;
        cin >> x0 >> x1 >> x2 >> x3;
        cout << n * (n + 1) / 2 << '\n';
    }
    return 0;
}

/*
dp, segment tree, hash, kmp, maths, greedy, graph
*/
